Skip to content

Conversation

EgonD3V
Copy link
Contributor

@EgonD3V EgonD3V commented Oct 26, 2024

답안 제출 문제

체크 리스트

  • PR을 프로젝트에 추가하고 Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 Status를 In Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@EgonD3V EgonD3V added the py label Oct 26, 2024
@EgonD3V EgonD3V requested a review from Sunjae95 October 26, 2024 14:57
@EgonD3V EgonD3V self-assigned this Oct 26, 2024
@EgonD3V EgonD3V requested a review from a team as a code owner October 26, 2024 14:57
@EgonD3V EgonD3V changed the title Feat/week11 [EGON] Week11 Solutions Oct 26, 2024
Comment on lines +65 to +68
root = unionFind.find(0)
for i in range(1, n):
if unionFind.find(i) != root:
return False
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 edges의 길이가 N-1개 미만인지 아닌지로 체크할 수도 있지만, union-find 쓰는데 통일해서 사용했습니다

Copy link
Contributor

@HC-kang HC-kang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lymchgmk 님 지난주도 고생 많으셨습니다!
이제 정말 거의 끝이 보이는데, 이번 주도 잘 부탁드립니다!

"""
def solve_union_find(self, n: int, edges: List[List[int]]) -> bool:

class UnionFind:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 유니온파인드를 클래스로 만들어두고 풀이하셨네요

LintCode 로그인이 안되어서 https://neetcode.io/problems/valid-tree에서 실행시키고 통과만 확인했습니다.

Runtime: ? ms (Beats ?%)
Time Complexity: O(max(m, n))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

설명을 자세히 적어주셔서 좋네요! 감사합니다!
다만 이 문제의 경우 edges.length = n-1이라는 조건이 있으니, O(n)으로 단순화 할 수 있을것으로 보입니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

간선의 총 갯수가 n-1개가 아닌 케이스가 있었던 것 같은데... 예를 들어 서로 분리된 유효한 트리 2개인 경우나, example2의 TC도 있었습니다.
Input: n = 5 edges = [[0, 1], [1, 2], [2, 3], [1, 3], [1, 4]]
Output: false.

elif new_e < s:
if new_s != -1 and new_e != -1:
result.append([new_s, new_e])
new_s = new_e = -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1이 뭔가 했네요.
굉장히 스마트한 풀이이긴 한데, 주석이나 변수명으로 안내를 해주시면 좀 더 좋을 것 같아요!

Space Complexity: O(n)
> 역방향 링크드 리스트인 backward를 생성하는데, backward의 길이는 원본 링크드 리스트의 길이와 같으므로 O(n)
"""
def solve(self, head: Optional[ListNode]) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 다른분들과 다른 새로운 풀이네요!
잘 보고 갑니다!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backward를 생성하는 풀이방법 충분히 납득되는 풀이방법이네요.👍

Copy link
Member

@Sunjae95 Sunjae95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이번주도 수고많으셨습니다! 🙂

Space Complexity: O(n)
> 역방향 링크드 리스트인 backward를 생성하는데, backward의 길이는 원본 링크드 리스트의 길이와 같으므로 O(n)
"""
def solve(self, head: Optional[ListNode]) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backward를 생성하는 풀이방법 충분히 납득되는 풀이방법이네요.👍

@EgonD3V EgonD3V merged commit 0633719 into DaleStudy:main Oct 30, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

3 participants